Skip to content

gh-116535: Fix distracting "TypeError" in example code#116536

Closed
dec1 wants to merge 1 commit into
python:mainfrom
dec1:dataclass_doc_example
Closed

gh-116535: Fix distracting "TypeError" in example code#116536
dec1 wants to merge 1 commit into
python:mainfrom
dec1:dataclass_doc_example

Conversation

@dec1

@dec1 dec1 commented Mar 9, 2024

Copy link
Copy Markdown
Contributor

Fix
TypeError: 'int' object is not iterable
raised when you call the sample code:

Note this is not the advertised (and expected) ValueError, which is fixed by using field

@dataclass
class D:
    x: list = []      # This code no longer raises ValueError
    def add(self, element):
        self.x += element # calling this (with an int element) raises TypeError

📚 Documentation preview 📚: https://cpython-previews--116536.org.readthedocs.build/

@dec1 dec1 requested a review from ericvsmith as a code owner March 9, 2024 09:30
@ghost

ghost commented Mar 9, 2024

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant